package com.simple.indiapay.catchs;

import com.google.common.base.Throwables;
import com.simple.common.entity.ResData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Objects;

/**
 * @author yasud
 * @date 2020年09月03日 14:10
 * @description
 */
@RestControllerAdvice
public class MyExceptionAfter {


    @ExceptionHandler
    public ResData handle(Exception ex) {
        ex.printStackTrace();
        Throwable rootCause = Throwables.getRootCause(ex);
        if (Objects.nonNull(rootCause)) {
            return ResData.error(rootCause.getMessage());
        }
        else return ResData.error("null 错误");
    }
}
